package com.xw.bo.ks.controller;

import com.xw.bo.ks.entity.base.HeadData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class BaseController {

    @Value("${ks.dsAuth.head.idReplace:false}")
    private boolean idReplace;

    @Value("${ks.dsAuth.head.channelId:0}")
    private Integer channelConfigurationId;

    @Value("${ks.dsAuth.head.partnerId:0}")
    private Integer partnerConfigurationId;

    @Value("${ks.dsAuth.head.mainId:0}")
    private Integer mainConfigurationId;

    public static ThreadLocal<String> dsAuth = new ThreadLocal();
    public static ThreadLocal<String> JSESSIONID = new ThreadLocal();
    public static ThreadLocal<String> token = new ThreadLocal();
    public static ThreadLocal<HeadData> headDataLocal = new ThreadLocal();


    /**
     * 获取请求头中的requestId
     *
     * @return 字符串
     */
    public String getRequestId() {

        HeadData headData = headDataLocal.get();

        String requestId = headData.getRequestId();
        if (StringUtils.isEmpty(requestId)) {
            log.error("请求头中的request_id为空，dsAuth = {}", dsAuth);
        }
        return requestId;
    }

    /**
     * aes解密请求头DsAuth中的密文
     *
     * @return 明文
     */
    public String getDsAuthAes() {
        return dsAuth.get();
    }



    public String returnResult(boolean result,String proMsg){
        if (result){
            return String.format("%s成功",proMsg);
        }
        return String.format("%s失败",proMsg);
    }

}
